package main

import (
	// "net/http"
	// "encoding/json"
	// "strconv"
	// "time"
	// "github.com/dgrijalva/jwt-go"
	// "github.com/labstack/echo"
	"gopkg.in/mgo.v2/bson"
	// "github.com/jinzhu/gorm"
	"oxy_server/module/log"
	"oxy_server/model"
	"golang.org/x/crypto/bcrypt"
)

type (
	user struct {
		ID bson.ObjectId `json:"_id" bson:"_id"`
		Name string `json:"username" bson:"username"`
		Password string `json :"password" bson :"password"`
		Role    string  `json:"role" bson:"role"`
		Email string    `json:"email" bson:"email"`
		Phone string    `json:"phone" bson:"phone"`
	}
	
)


func main() {
	model.DB().Dbname="OxyCms"
	model.DB().Document="users"
	query,count,err:=model.DB().Query(nil,0 ,0 )
	log.Info("count",count)
	if err != nil {
		log.Error("查询出错",err)
	}
	ps:=[]user{}
	query.All(&ps)
	for key,e := range ps {
		log.Info("key",key)
		log.Info("e",e)
		bytes, err := bcrypt.GenerateFromPassword([]byte(e.Password), bcrypt.DefaultCost)
		e.Password = string(bytes)

		err = model.DB().Update(bson.M{"_id":e.ID} , e)
		if err != nil{
			log.Error("插入失败",err)
			return
		}
	}
	log.Info("success")
}